<?php

/**
 * paypal记录
 */
class Application_Model_PaypalLog extends Application_Model_DomainObject {
    
    protected $_id;
    protected $_txnId;          //paypal流水号
    protected $_dateCreated;    //paypal交易时间
    protected $_paypalName;     //paypal用户名
    protected $_amount;         //paypal总金额
    protected $_paypalStatus;   //paypal状态
    protected $_paypalEmail;    //paypal用户邮箱
    protected $_feeAmt;         //paypal手续费
    protected $_status;         //状态
    protected $_operator;       //操作人
    protected $_isDel;          //是否删除
    /**
     * 默认
     */
    const Status_Default = 0;
    /**
     * 系统已处理
     */
    const Status_System = 1;    
    /**
     * 手工处理
     */
    const Status_Manual = 2;
    /**
     * 忽略
     */
    const Status_Ignore = 3;
    
    public static function getAllStatus()
    {
        return array(
                   self::Status_Default => "默认"
                ,  self::Status_System => "系统已处理"
                ,  self::Status_Manual => "手工处理"
                ,  self::Status_Ignore => "忽略"
        );
    }
    
    public function getStatusName()
    {
        $arrStatus = self::getAllStatus();
        $return = array_key_exists($this->_status, $arrStatus)?$arrStatus[$this->_status]:false;
        return $return;
    }
    
    public static function getAllPaypalStatus()
    {
        return array(
                "Completed" => "已完成"
               ,"Refunded" => "已退款"
               ,"Pending" => "待处理"
               ,"Unclaimed" => "待领取"
               , "Uncleared" => "已结清"
        );
    }
    
    public function getPaypalStatusName()
    {
        $arrPaypalStatus = self::getAllPaypalStatus();
        return array_key_exists($this->_paypalStatus, $arrPaypalStatus)?$arrPaypalStatus[$this->_paypalStatus]:false;
    }
    
    public static function getFilter($quick, $dateinbegin,$paypalStatus, $status,$dateinend, $pagesize, $pageindex)
    {
        $where = array();
        $and = "";
        if($quick != ""){
            $where["( txnId like "] = "%".$quick."%";
            $where[" or paypalName like "] = "%".$quick."%";
            $where[" or paypalEmail like "] = "%".$quick."%";
            $where[" ) and "] = 1;
            $and = " and ";
        }
        if ($dateinbegin != "") {
            $where[$and . " dateCreated >= "] = $dateinbegin;
            $and = " and ";
        }
        if ($dateinend != "") {
            $where[$and . " dateCreated <= "] = $dateinend;
            $and = " and ";
        }
        if($paypalStatus != ""){
            $where[$and." paypalStatus = "] = $paypalStatus;
            $and = " and ";
        }
        if($status != ""){
            $where[$and." status = "] = $status;
            $and = " and ";
        }
        return self::getDao()->queryPage($where, "dateCreated desc", $pagesize, $pageindex);
    }
    
    public static function byTxnId($txnId)
    {
        return self::getDao()->queryOne(array("txnId = "=> $txnId));
    }

}